
import http from "@/utils/request";

import { AddUser } from '@/types/index'

//获取当前登录用户信息
export const Person = () => {
    return http.get("/prod-api/api/v1/users/me")
}

//获取用户分页列表
// export const getUserPage = () => {
//     return http.get("/api/v1/users/page")
// }

//获取部门树列表

export const getDeptTree = () => {
    return http({
        url: "/youlai-system/api/v1/dept",
        method: "get",
        headers: {
            Authorization: localStorage.getItem("token")
        }
    })
}

//删除用户
// export const delUser = (ids: number) => {
//     return http.delete("/api/v1/users/" + ids)
// }

//新增用户

// export const addUser = (query:{AddUser: any})=>{
//     return http.post("/api/v1/users",query)
// }

//角色列表
export const getroles = () => {
    return http({
        url: "/youlai-system/api/v1/roles/pages",
        method: "get",
        headers: {
            Authorization: localStorage.getItem("token")
        }
    })
}



//源码

import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { UserForm, UserInfo, UserPageVO, UserQuery } from './types';

/**
 * 登录成功后获取用户信息（昵称、头像、权限集合和角色集合）
 */
export function getUserInfo(): AxiosPromise<UserInfo> {
    return request({
        url: '/prod-api/api/v1/users/me',
        method: 'get',
        headers: {
            Authorization: localStorage.getItem("token")
        }
    });
}

/**
 * 获取用户分页列表
 *
 * @param queryParams
 */
export function getUserPage(
    queryParams: UserQuery
): AxiosPromise<UserPageVO[]> {
    return request({
        url: '/youlai-system/api/v1/users/pages',
        method: 'get',
        params: queryParams,
        headers: {
            Authorization: localStorage.getItem("token")
        }
    });
}

/**
 * 获取用户表单详情
 *
 * @param userId
 */
export function getUserForm(userId: number): AxiosPromise<UserForm> {
    return request({
        url: '/youlai-system/api/v1/users/' + userId + '/form',
        method: 'get',
        headers: {
            Authorization: localStorage.getItem("token")
        }
    });
}

/**
 * 添加用户
 *
 * @param data
 */
export function addUser(data: any) {
    return request({
        url: '/youlai-system/api/v1/users',
        method: 'post',
        data: data,
        headers: {
            Authorization: localStorage.getItem("token")
        }
    });
}

/**
 * 修改用户
 *
 * @param id
 * @param data
 */
export function updateUser(userId: number, data: UserForm) {
    return request({
        url: '/youlai-system/api/v1/users/' + userId,
        method: 'put',
        data: data,
        headers: {
            Authorization: localStorage.getItem("token")
        }
    });
}

/**
 * 修改用户状态
 *
 * @param id
 * @param status
 */
export function updateUserStatus(userId: number, status: number) {
    return request({
        url: '/youlai-system/api/v1/users/' + userId + '/status',
        method: 'patch',
        params: { status: status },
        headers: {
            Authorization: localStorage.getItem("token")
        }
    });
}

/**
 * 修改用户密码
 *
 * @param id
 * @param password
 */
export function updateUserPassword(userId: number, password: string) {
    return request({
        url: '/youlai-system/api/v1/users/' + userId + '/password',
        method: 'patch',
        params: { password: password },
        headers: {
            Authorization: localStorage.getItem("token")
        }
    });
}

/**
 * 删除用户
 *
 * @param ids
 */
export function deleteUsers(userId: string) {
    return request({
        url: '/youlai-system/api/v1/users/' + userId,
        method: 'delete',
        headers: {
            Authorization: localStorage.getItem("token")
        }
    });
}

/**
 * 下载用户导入模板
 *
 * @returns
 */
export function downloadTemplateApi() {
    return request({
        url: '/youlai-system/api/v1/users/template',
        method: 'get',
        responseType: 'arraybuffer',
        headers: {
            Authorization: localStorage.getItem("token")
        }
    });
}

/**
 * 导出用户
 *
 * @param queryParams
 * @returns
 */
// export function exportUser(queryParams: UserQuery) {
//   return request({
//     url: '/api/v1/users/_export',
//     method: 'get',
//     params: queryParams,
//     responseType: 'arraybuffer'
//   });
// }

/**
 * 导入用户
 *
 * @param file
 */
export function importUser(deptId: number, file: File) {
    const formData = new FormData();
    formData.append('file', file);
    return request({
        url: '/youlai-system/api/v1/users/_import',
        method: 'post',
        params: { deptId: deptId },
        data: formData,
        headers: {
            Authorization: localStorage.getItem("token")
        }
    });
}


